package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
	"gitee.com/aldrice/monitor/internal/monitor/definition"
)

// Setting holds the schema definition for the Setting entity.
type Setting struct {
	ent.Schema
}

// Fields of the Setting.
func (Setting) Fields() []ent.Field {
	return []ent.Field{
		field.String("nickname"),

		field.Int("length").Min(0).Comment("聚合的时间片长度 单位: 分钟"),
		field.Enum("method").Values(definition.Methods...).Comment("聚合的方法"),
		field.Bool("enable").Default(true),
	}
}

// Edges of the Setting.
func (Setting) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("with_object", Object.Type).Unique(),
		edge.To("with_metric", Metric.Type).Unique(),
	}
}

func (Setting) Indexes() []ent.Index {
	return []ent.Index{
		index.Edges("with_object", "with_metric").Fields("method").Unique(),
	}
}
